package model

import (
	"fmt"
	"time"

	"../../job/pkg/settings"
)

/**
	配置定时任务时间
 */

type CronTime struct {
	Id          int64
	UrlTime     string    `xorm:"varchar(100) 'urlTime'"`   //url定时任务时间间隔
	EmailTime   string    `xorm:"varchar(100) 'emailTime'"` //发送邮件时间间隔
	ReqTime     string    `xorm:"varchar(100) 'reqTime'"`   //url请求时间间隔
	CreatedTime time.Time `xorm:"createdTime"`
	UpdatedTime time.Time `xorm:"updatedTime"`
}

func AddCronTime(k, v string) {
	sql := "replace into cron_time where %s = %s"
	settings.MasterDB.Exec(fmt.Sprintf(sql, k, v))
}

func GetCronTime() map[string]string {
	strings, err := settings.MasterDB.QueryString("select * from cron_time ")
	fmt.Println("定时任务启动")
	if err != nil {
		fmt.Println(err)
	}

	return strings[0]

}
